<?php
/**
 * Created by PhpStorm.
 * User: peter
 * Date: 2018/7/3
 * Time: 下午7:01
 */

namespace app\mall\controller;


use app\mall\logic\Withdraw;
use think\Request;

class Profit extends Auth
{
    /**
     * @purpose 获取账户资金
     * @return array
     */
    public function account ()
    {
        return \app\mall\logic\Profit::account(self::$uid);
    }

    /**
     * @purpose 获取待转入的资金列表
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function waitRecordItem (Request $request)
    {
        $page           = $request->get('page', 1);
        $size           = $request->get('size', 50);
        return \app\mall\logic\Profit::waitRecordItem(self::$uid, $page, $size);
    }

    /**
     * @purpose 获取用户收入列表
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function income (Request $request)
    {
        $page           = $request->get('page', 1);
        $size           = $request->get('size', 50);
        return \app\mall\logic\Profit::income(self::$uid, $page, $size);
    }

    /**
     * @purpose  用户申请提现
     * @param Request $request
     * @return array
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function withdraw (Request $request)
    {
        $quota          = $request->post('quota',0);
        $quota          = (int)($quota * 100);
        return Withdraw::withdraw($quota, self::$uid);
    }

    /**
     * @purpose 获取提醒记录
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function withdrawRecord (Request $request)
    {
        $page           = $request->get('page', 1);
        $size           = $request->get('size', 50);
        return Withdraw::items(self::$uid,$page,$size);
    }
}